# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html

import json;

class MycrawlerPipeline(object):
    #def __init__(self):
        #self.file = open('test.json', 'wb')

    def process_item(self, item, spider):
        str = ''
        if( item['kind'] == 2 ):
            self.file = open('Version.json','a')
            #str = self.file.read()

        if( item['kind'] == 3):
            self.file = open('Chapter.json','a')
            #str = self.file.read()

        if( item['kind'] == 4):
            self.file = open('Problem.json','a')
            #str = self.file.read()

        line = json.dumps(dict(item), ensure_ascii=False).encode('utf8') + "\n"
        self.file.write(line)
        return item
    def spider_closed(self, spider):
        self.file.close()